package com.itdianzi.service.company.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itdianzi.domain.company.Company;
import com.itdianzi.dao.company.CompanyDao;
import com.itdianzi.service.company.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Override
    public PageInfo findAll(Integer page, Integer size) {
//        调用分页插件的方法，自动帮助我们分页
        PageHelper.startPage(page, size);
        //紧跟在这个方法后的第一个MyBatis查询方法会被进行分页，查询所有即可
        List<Company> companyList =companyDao.findAll();
        System.out.println(companyList);
        //返回分页的数据
        PageInfo pageInfo = new PageInfo(companyList);
        return pageInfo;
    }

    @Override
    public void save(Company company) {
        /*获取随机ID*/
        String s = UUID.randomUUID().toString();
        company.setId(s);
        companyDao.save(company);
    }

    @Override
    public Company findById(String id) {
        return companyDao.findById(id);
    }

    @Override
    public void upDate(Company company) {
        companyDao.upDate(company);
    }

    @Override
    public void deleteById(String id) {
        companyDao.deleteById(id);
    }

    @Override
    public PageInfo findByPage(Integer page, Integer size) {
        System.out.println(123132);
        PageHelper.startPage(page, size);
        List<Company> companyDaoAll = companyDao.findAll();
        PageInfo pageInfo = new PageInfo(companyDaoAll);
        return pageInfo;
    }
}
